home *** CD-ROM | disk | FTP | other *** search
- /*
- cycle.c - color cycling on 640x350 16 color image
- reads full-screen .MJB image written by LBM2BGI.EXE
- marty balash
- 03/02/91
-
- ******** NEED TO LINK IN EGAVGA.BGI
- */
-
- #include <graphics.h>
- #include <alloc.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <io.h>
-
- struct IMAGEHDR{
- char id[8]; /* id - use this for verifying format */
- unsigned size; /* size - bytes to malloc */
- struct palettetype palette; /* palette - for image */
- }hdr;
-
- main()
- {
- if(!openegascreen()) /* open 16 color 640x350 screen */
- exit(255);
-
- printhelp(); /* show message while loading file */
-
- setactivepage(1); /* send all graphics output other page */
-
- if(!showpic("cycle.mjb")) /* put bgi images on page */
- exit(255);
-
- puts("\nPRESS ANY KEY...\n"); /* graphics loaded */
- getch();
-
- setvisualpage(1); /* show other page */
-
- cycle(); /* alternate colors in palette */
-
- closegraph();
- }
-
- printhelp()
- {
- puts("Faster - CSR UP");
- puts("Slower - CSR DOWN\n");
- puts("Exit - ESC\n\n");
- puts("PLEASE WAIT...");
- }
-
- cycle()
- {
- int i;
- char ch;
- signed char lastcolor;
- unsigned pause=60;
-
- while(1){
- while(!kbhit()){
- lastcolor=hdr.palette.colors[0];
- for(i=0;i<16;i++)
- hdr.palette.colors[i]=hdr.palette.colors[i+1];
- hdr.palette.colors[15]=lastcolor;
- setallpalette(&(hdr.palette));
- delay(pause);
- }
- if((ch=getch())==27)
- break;
- if(ch==32||ch==13)
- break;
- if(ch==80)
- pause++;
- if(ch==72)
- pause--;
- if(pause<0)
- pause=250;
- if(pause>250)
- pause=0;
- }
- }
-
- showpic(s)
- char *s;
- {
- int datahandle,i;
- char *buff;
- long fl;
-
- if((datahandle=open(s,O_RDONLY|O_BINARY))==-1){
- closegraph();
- puts("Can't Find File CYCLE.MJB");
- return(0);
- }
- if (filelength(datahandle)<30000L){
- close(datahandle);
- closegraph();
- printf("ERROR: This isn't a full-screen image\n");
- exit(255);
- }
- read(datahandle,&hdr,sizeof(hdr)); /* read header struct */
- if(strcmp(hdr.id,"PCX2BGI")!=0){ /* this should always be "PCX2BGI" */
- closegraph();
- close(datahandle);
- printf("Invalid picture format\n");
- exit(255);
- }
- setallpalette(&(hdr.palette));
- if((buff=malloc(22406))==NULL){ /* malloc enough for 1/5 of screen */
- close(datahandle);
- closegraph();
- puts("Can't Allocate Memory");
- return(0);
- }
- for(i=0;i<350;i+=70){ /* read 5 consecutive bgi images from file */
- read(datahandle,buff,22406);
- putimage(0,i,buff,COPY_PUT);
- }
- free(buff);
- close(datahandle);
- return(1);
- }
-
- openegascreen()
- {
- int driver = EGA;
- int mode = EGAHI;
- int result;
-
- /* init graphics system */
- if (registerbgidriver(EGAVGA_driver)<0){
- printf("ERROR: Graphics System\n");
- return(0);
- }
- initgraph(&driver,&mode,"");
- result=graphresult();
- if (result!=grOk) {
- printf("ERROR : %s\n",grapherrormsg(result));
- return(0);
- }
- return(1);
- }
-